package com.example.validproject.protocol;

/**
 * @author kh
 * Created by on  2021-09-27 10:50
 */
public enum BaseErrorCode implements IErrorCode {

    /**
     * 操作成功
     */
    SUCCESS("200", "操作成功"),
    /**
     * 业务异常
     */
    INTERNAL_BUSSINESS_ERROR("201", "业务异常"),
    /**
     * 服务器内部错误
     */
    INTERNAL_SERVER_ERROR("500", "服务器内部错误"),
    /**
     * 服务器内部调用错误
     */
    INTER_REMOTE_ERROR("600", "服务内部调用错误"),
    PARAM_ERROR("700", "参数校验错误"),
    /**
     * 服务器内部系统错误
     */
    SYSTEM_ERROR("900", "系统错误");

    private final String code;

    private final String message;

    BaseErrorCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * Return the integer value of this status code.
     */
    @Override
    public String getCode() {
        return this.code;
    }

    /**
     * Return the reason phrase of this status code.
     */
    @Override
    public String getMessage() {
        return this.message;
    }

    public static IErrorCode getByCode(String code) {
        for (IErrorCode iErrorCode : values()) {
            if (code == iErrorCode.getCode()) {
                return iErrorCode;
            }
        }

        return BaseErrorCode.INTERNAL_SERVER_ERROR;
    }
}
